package com.fira.edu.service.impl;

import java.util.List;
import com.fira.common.utils.DateUtils;
import com.fira.common.utils.uuid.IdUtils;
import com.fira.edu.domain.EduStudent;
import com.fira.edu.mapper.EduStudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fira.edu.mapper.EduMessageBoardMapper;
import com.fira.edu.domain.EduMessageBoard;
import com.fira.edu.service.IEduMessageBoardService;
import com.fira.common.core.text.Convert;

/**
 * 留言板Service业务层处理
 * 
 * @author zhushuyong
 * @date 2021-10-20
 */
@Service
public class EduMessageBoardServiceImpl implements IEduMessageBoardService 
{
    @Autowired
    private EduMessageBoardMapper eduMessageBoardMapper;
    @Autowired
    private EduStudentMapper eduStudentMapper;

    /**
     * 查询留言板
     * 
     * @param id 留言板ID
     * @return 留言板
     */
    @Override
    public EduMessageBoard selectEduMessageBoardById(String id)
    {
        return eduMessageBoardMapper.selectEduMessageBoardById(id);
    }

    /**
     * 查询留言板列表
     * 
     * @param eduMessageBoard 留言板
     * @return 留言板
     */
    @Override
    public List<EduMessageBoard> selectEduMessageBoardList(EduMessageBoard eduMessageBoard)
    {
        return eduMessageBoardMapper.selectEduMessageBoardList(eduMessageBoard);
    }

    /**
     * 新增留言板
     * 
     * @param eduMessageBoard 留言板
     * @return 结果
     */
    @Override
    public int insertEduMessageBoard(EduMessageBoard eduMessageBoard)
    {
        //查询学生所在的租户
        EduStudent student = eduStudentMapper.selectEduStudentById(eduMessageBoard.getStudentId());
        if(student == null){
            return 0;
        }
        eduMessageBoard.setId(IdUtils.fastSimpleUUID());
        eduMessageBoard.setTenantId(student.getTenantId());
        eduMessageBoard.setSendTime(DateUtils.getNowDate());
        eduMessageBoard.setCreateTime(DateUtils.getNowDate());
        return eduMessageBoardMapper.insertEduMessageBoard(eduMessageBoard);
    }

    /**
     * 修改留言板
     * 
     * @param eduMessageBoard 留言板
     * @return 结果
     */
    @Override
    public int updateEduMessageBoard(EduMessageBoard eduMessageBoard)
    {
        eduMessageBoard.setUpdateTime(DateUtils.getNowDate());
        return eduMessageBoardMapper.updateEduMessageBoard(eduMessageBoard);
    }

    /**
     * 删除留言板对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteEduMessageBoardByIds(String ids)
    {
        return eduMessageBoardMapper.deleteEduMessageBoardByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除留言板信息
     * 
     * @param id 留言板ID
     * @return 结果
     */
    @Override
    public int deleteEduMessageBoardById(String id)
    {
        return eduMessageBoardMapper.deleteEduMessageBoardById(id);
    }
}
